<template>
  <Dialog :title="t('judgeScene.initial.resultDetail')" v-model="dialogVisible" width="1000">
    <vxe-table
      id="iCandidateResultDetail-table"
      ref="tableRef"
      v-loading="loading"
      :data="list"
      stripe
      :custom-config="vxeTableConfig"
      :column-config="{ resizable: true }"
      :size="vxeTableSize"
    >
      <vxe-column :title="t('common.index')" type="seq" field="seq" width="60" align="center" />
      <vxe-column
        :title="t('candidate.resultDetail.field.mentorName')"
        field="mentorName"
        align="center"
        show-header-overflow
        show-overflow
        min-width="100"
      />
      <vxe-column
        :title="t('candidate.resultDetail.field.mentorCode')"
        field="mentorCode"
        align="center"
        show-header-overflow
        show-overflow
        min-width="100"
      />
      <vxe-column
        :title="t('candidate.resultDetail.field.value')"
        field="value"
        align="center"
        show-header-overflow
        show-overflow
        min-width="100"
      />
      <vxe-column
        :title="t('candidate.resultDetail.field.confirmResult')"
        field="confirmResult"
        align="center"
        show-header-overflow
        show-overflow
        min-width="100"
      >
        <template #default="scope">
          <span v-if="scope.row.confirmResult">{{ t('common.yes') }}</span>
          <span v-else>{{ t('common.no') }}</span>
        </template>
      </vxe-column>
    </vxe-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </Dialog>
</template>

<script setup lang="ts">
import type { VxeTableInstance, VxeTablePropTypes } from 'vxe-table'
import { useAppStore } from '@/store/modules/app'
import {
  CandidateAdminRespVO,
  JudgesSubmitDetailsResVO,
  ReviewSceneApi
} from '@/api/awards/reviewscene'

defineOptions({ name: 'CandidateResultDetail' })

const route = useRoute()
const router = useRouter() // 路由对象
const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const tableRef = ref<VxeTableInstance>()

const dialogVisible = ref(false)
const loading = ref(true) // 列表的加载中
const list = ref<JudgesSubmitDetailsResVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  awardsInstanceId: undefined,
  roundId: undefined,
  awardsCandidateId: undefined
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

const vxeTableConfig: VxeTablePropTypes.CustomConfig = {
  storage: true,
  mode: 'drawer',
  checkMethod({ column }) {
    return !['seq', 'operator'].includes(column.field)
  }
}

const appStore = useAppStore()
const vxeTableSize = computed(() => appStore.getCurrentSizeVxe)

/** 查询列表 */
const getList = async () => {
  loading.value = true
  queryParams.awardsInstanceId = row.value!.awardId as any
  queryParams.roundId = roundId.value as any
  queryParams.awardsCandidateId = row.value!.id as any
  try {
    const data = await ReviewSceneApi.getJudgesSubmitDetails(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

const row = ref<CandidateAdminRespVO>()
const roundId = ref('')
const open = (_row: CandidateAdminRespVO, _roundId: string) => {
  row.value = _row
  roundId.value = _roundId
  reset()
  dialogVisible.value = true
  getList()
}

const reset = () => {
  queryParams.pageNo = 1
  queryParams.pageSize = 10
  list.value = []
  total.value = 0
}

defineExpose({ open })
</script>
